#coding:utf-8

from flask import Flask, request
import casePlanBussiness
import json,time
import appconf,hashlib,os
from flask import send_from_directory

app = appconf.app



@app.route('/casePlan/main/process/srh')
def casePlan_main_process_srh():
    id = request.args.get("id")
    t = request.args.get("t")
    item = casePlanBussiness.case_plan_process_all(id,t=t)
    return json.dumps({'errorCode': '', 'data':item})

@app.route('/casePlan/main/srh')
def casePlan_main_srh():
    project_id = request.args.get("project_id")
    work_state = request.args.get("work_state")
    work_p_start = request.args.get("work_p_start")
    work_p_end = request.args.get("work_p_end")
    key_words = request.args.get("key_words")
    page = request.args.get("page")
    limit = request.args.get("limit")
    items = casePlanBussiness.case_plan_srh(project_id,work_state,work_p_start,work_p_end,key_words,page,limit)
    return json.dumps({'errorCode': '', 'data':items[0],"count":items[1] })

@app.route('/casePlan/sub/srh')
def casePlan_sub_srh():
    case_main_id = request.args.get("case_main_id")
    items = casePlanBussiness.case_sub_plan_srh(case_main_id)
    return json.dumps({'errorCode': '', 'data': items})



@app.route('/casePlan/main/manage', methods=['POST'])
def casePlan_main_mainage():
    content = request.json
    id = casePlanBussiness.casePlan_main_manage(content)
    return json.dumps({'errorCode': '', 'id': id})

@app.route('/casePlan/sub/manage', methods=['POST'])
def casePlan_sub_mainage():
    content = request.json
    id = casePlanBussiness.casePlan_sub_manage(content)
    return json.dumps({'errorCode': '', 'id': id})

@app.route('/casePlan/main/process/manage', methods=['POST'])
def casePlan_main_process_mainage():
    content = request.json
    id = casePlanBussiness.case_plan_process_manage(content)
    return json.dumps({'errorCode': '', 'id': id})

@app.route('/casePlan/sub/delete', methods=['POST'])
def casePlan_sub_delete():
    content = request.json
    id = casePlanBussiness.case_plan_sub_delete(content['id'])
    return json.dumps({'errorCode': '', 'id': id})


@app.route('/total/userId')
def total_byUserId():
    id = request.args.get("id")
    data = casePlanBussiness.case_sys_total_byme(id)
    return json.dumps({'errorCode': '', 'id': data})

@app.route('/total/user/order')
def total_order():
    data = casePlanBussiness.case_sys_order()
    return json.dumps({'errorCode': '', 'data': data})

@app.route('/total/project/order')
def total_project_order():
    data = casePlanBussiness.case_sys_orderByPjt()
    return json.dumps({'errorCode': '', 'data': data})

@app.route('/total/allUser/order')
def total_allUser_order():
    data = casePlanBussiness.case_sys_allUserOrder()
    return json.dumps({'errorCode': '', 'data': data})